// const baseUrl = 'https://2c.mirrorego.com/'
import {
	baseRequestDomain
} from './config.js'

const request = ({
	method = 'GET',
	url,
	data = {},
	header = {}
}) => {
	header.Authorization = `Bearer ${uni.getStorageSync('larsonToken')}`;
	header.token = uni.getStorageSync('larsonToken');
	
	const userInfo = uni.getStorageSync('userInfo') || '{}';
	const { eAppId, orgId } = JSON.parse(userInfo); 
	header.appId = eAppId;
	header.orgId = orgId;
	header['Accept-Language'] = "zh_CN"
	return new Promise((resolve, reject) => {
		uni.request({
			url: url.includes('http') ? url : `${baseRequestDomain}${url}`, //仅为示例，并非真实接口地址。,
			method,
			data,
			header,
			success: res => {
				if (res.data?.code === 200 || res.data?.code === 0) {
					resolve(res.data);
					return;
				}
				uni.showToast({ title: res.data?.msg || '服务器异常，请稍后重试', icon: 'none' });
				reject(res);
			},
			fail: err => {
				uni.showToast({ title: res.data?.msg || '服务器异常，请稍后重试', icon: 'none' });
				reject(err)
			},
			complete: () => {}
		})
	})
}

uni.$request = request;
export default request;